package com.jiazhong.controller.safty;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jiazhong.base.Constant;
import com.jiazhong.base.Constants;
import com.jiazhong.base.CurrUser;
import com.jiazhong.base.Result;
import com.jiazhong.exception.LoginException;
import com.jiazhong.exception.SysException;
import com.jiazhong.service.safty.LoginService;
import com.jiazhong.view.UserView;

@RestController
@RequestMapping("/safty/login")
public class LoginController {
	@Autowired
	private LoginService loginService;
	@PostMapping("/login")
	public Result login(@RequestBody UserView userView,HttpSession session) {
		try {
			CurrUser currUser = loginService.login(userView);
			//将用户存入到session中
			session.setAttribute(Constants.SESSION_ATTR_CURRUSER, currUser);
			return Result.success("登录成功!");
		}catch (SysException e) {
			return Result.fail("系统升级中........");
		}catch(LoginException e) {
			return Result.fail(e.getMessage());
		}
		
	}

}
